﻿namespace WMS6.Web
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web;
    using WMS6.Web.BaseInfoDetailServiceRef;

    public class BaseInfoDetailServiceClientProxy : BasePage
    {
        public string DeleteDetail(List<string> mainID, List<string> subID, List<string> pk3, string className)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BaseInfoDetailServiceClient client = new BaseInfoDetailServiceClient("WSHttpBinding_IBaseInfoDetailService");
            try
            {
                result = client.DeleteDetail(mainID, subID, pk3, className, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public DataSet GetAllDetailInfo(string className)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            BaseInfoDetailServiceClient client = new BaseInfoDetailServiceClient("WSHttpBinding_IBaseInfoDetailService");
            try
            {
                ds = client.GetAllDetailInfo(className, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetDetaiInfolByQueryEntity(object obj, string className)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            BaseInfoDetailServiceClient client = new BaseInfoDetailServiceClient("WSHttpBinding_IBaseInfoDetailService");
            try
            {
                ds = client.GetDetaiInfolByQueryEntity(obj, className, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public object GetDetailInfoByID(string id, string subID, string pk3, string className)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            object obj = null;
            BaseInfoDetailServiceClient client = new BaseInfoDetailServiceClient("WSHttpBinding_IBaseInfoDetailService");
            try
            {
                obj = client.GetDetailInfoByID(id, subID, pk3, className, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return obj;
        }

        public List<object> GetDetailInfoListByID(string mainID, string subID, string className)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            List<object> objectList = null;
            BaseInfoDetailServiceClient client = new BaseInfoDetailServiceClient("WSHttpBinding_IBaseInfoDetailService");
            try
            {
                objectList = client.GetDetailInfoListByID(mainID, subID, className, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return objectList;
        }

        public static BaseInfoDetailServiceClientProxy GetInstance()
        {
            return new BaseInfoDetailServiceClientProxy();
        }

        private PubParasInfo InitPubParasInfo()
        {
            if (base.UserInfo != null)
            {
                return new PubParasInfo { UserID = base.UserInfo.UserID, UserLanguage = base.UserInfo.Preference.Lang, CurrentWH = base.UserInfo.CurrentWH };
            }
            HttpContext.Current.Response.Redirect("../Login.aspx?from=Logout", true);
            return null;
        }

        public string InsertDetail(object obj, string className)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BaseInfoDetailServiceClient client = new BaseInfoDetailServiceClient("WSHttpBinding_IBaseInfoDetailService");
            try
            {
                result = client.InsertDetail(obj, className, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateDetail(object obj, string className)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BaseInfoDetailServiceClient client = new BaseInfoDetailServiceClient("WSHttpBinding_IBaseInfoDetailService");
            try
            {
                result = client.UpdateDetail(obj, className, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateIsActive(List<string> mainID, List<string> subID, string isActive, string className)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BaseInfoDetailServiceClient client = new BaseInfoDetailServiceClient("WSHttpBinding_IBaseInfoDetailService");
            try
            {
                result = client.UpdateIsActive(mainID, subID, isActive, className, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }
    }
}

